<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>boost/python/def_visitor.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../high_level_components.html" title="Chapter 2. High Level Components">
<link rel="prev" href="boost_python_def_hpp.html" title="boost/python/def.hpp">
<link rel="next" href="boost_python_docstring_options_h.html" title="boost/python/docstring_options.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_def_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_docstring_options_h.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="high_level_components.boost_python_def_visitor_hpp"></a><a class="link" href="boost_python_def_visitor_hpp.html" title="boost/python/def_visitor.hpp">boost/python/def_visitor.hpp</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="boost_python_def_visitor_hpp.html#high_level_components.boost_python_def_visitor_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_def_visitor_hpp.html#high_level_components.boost_python_def_visitor_hpp.class_def_visitor">Class
        <code class="computeroutput"><span class="identifier">def_visitor</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_def_visitor_hpp.html#high_level_components.boost_python_def_visitor_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_def_visitor_hpp.introduction"></a><a class="link" href="boost_python_def_visitor_hpp.html#high_level_components.boost_python_def_visitor_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
          &lt;boost/python/def_visitor.hpp&gt; provides a generic visitation interface
          through which the <a class="link" href="../high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel" title="Class template class_&lt;T, Bases, HeldType, NonCopyable&gt;">class_</a>
          def member functionality can be extended non-intrusively to avoid cluttering
          the <a class="link" href="../high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel" title="Class template class_&lt;T, Bases, HeldType, NonCopyable&gt;">class_</a>
          interface. It declares the <code class="computeroutput"><span class="identifier">def_visitor</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code> class template, which is parameterized
          on the derived type <code class="computeroutput"><span class="identifier">DerivedVisitor</span></code>,
          which provides the actual <code class="computeroutput"><span class="identifier">def</span></code>
          functionality through its <code class="computeroutput"><span class="identifier">visit</span></code>
          member functions.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_def_visitor_hpp.class_def_visitor"></a><a class="link" href="boost_python_def_visitor_hpp.html#high_level_components.boost_python_def_visitor_hpp.class_def_visitor" title="Class def_visitor">Class
        <code class="computeroutput"><span class="identifier">def_visitor</span></code></a>
</h3></div></div></div>
<p>
          The class <code class="computeroutput"><span class="identifier">def_visitor</span></code> is
          a base class paramaterized by its derived class. The <code class="computeroutput"><span class="identifier">def_visitor</span></code>
          class is a protocol class. Its derived class, DerivedVisitor, is expected
          to have a member function <code class="computeroutput"><span class="identifier">visit</span></code>.
          The <code class="computeroutput"><span class="identifier">def_visitor</span></code> class is
          never instantiated directly. Instead, an instance of its subclass, DerivedVisitor,
          is passed on as an argument to the <a class="link" href="../high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel" title="Class template class_&lt;T, Bases, HeldType, NonCopyable&gt;">class_</a>
          <code class="computeroutput"><span class="identifier">def</span></code> member function.
        </p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span> <span class="special">{</span>

    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">DerivedVisitor</span><span class="special">&gt;</span>
    <span class="keyword">class</span> <span class="identifier">def_visitor</span> <span class="special">{};</span>
<span class="special">}</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd>
<p>
                The client supplied class DerivedVisitor template parameter is expected
                to: * be privately derived from def_visitor * grant friend access
                to class def_visitor_access * define either or both visit member
                functions listed in the table below:
              </p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                        <p>
                          Expression
                        </p>
                      </th>
<th>
                        <p>
                          Return Type
                        </p>
                      </th>
<th>
                        <p>
                          Requirements
                        </p>
                      </th>
<th>
                        <p>
                          Effects
                        </p>
                      </th>
</tr></thead>
<tbody>
<tr>
<td>
                        <p>
                          <code class="computeroutput"><span class="identifier">visitor</span><span class="special">.</span><span class="identifier">visit</span><span class="special">(</span><span class="identifier">cls</span><span class="special">)</span></code>
                        </p>
                      </td>
<td>
                        <p>
                          <code class="computeroutput"><span class="keyword">void</span></code>
                        </p>
                      </td>
<td>
                        <p>
                          <code class="computeroutput"><span class="identifier">cls</span></code> is
                          an instance of a <a class="link" href="../high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel" title="Class template class_&lt;T, Bases, HeldType, NonCopyable&gt;">class_</a>
                          being wrapped to Python. <code class="computeroutput"><span class="identifier">visitor</span></code>
                          is a <code class="computeroutput"><span class="identifier">def_visitor</span></code>
                          derived class.
                        </p>
                      </td>
<td>
                        <p>
                          A call to <code class="computeroutput"><span class="identifier">cls</span><span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">visitor</span><span class="special">)</span></code> forwards to this member
                          function.
                        </p>
                      </td>
</tr>
<tr>
<td>
                        <p>
                          <code class="computeroutput"><span class="identifier">visitor</span><span class="special">.</span><span class="identifier">visit</span><span class="special">(</span><span class="identifier">cls</span><span class="special">,</span> <span class="identifier">name</span><span class="special">,</span> <span class="identifier">options</span><span class="special">)</span></code>
                        </p>
                      </td>
<td>
                        <p>
                          <code class="computeroutput"><span class="keyword">void</span></code>
                        </p>
                      </td>
<td>
                        <p>
                          <code class="computeroutput"><span class="identifier">cls</span></code> is
                          a <a class="link" href="../high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel" title="Class template class_&lt;T, Bases, HeldType, NonCopyable&gt;">class_</a>
                          instance, name is a C string. <code class="computeroutput"><span class="identifier">visitor</span></code>
                          is a <code class="computeroutput"><span class="identifier">def_visitor</span></code>
                          derived class. options is a context specific optional argument.
                        </p>
                      </td>
<td>
                        <p>
                          A call to <code class="computeroutput"><span class="identifier">cls</span><span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">name</span><span class="special">,</span> <span class="identifier">visitor</span><span class="special">)</span></code> or <code class="computeroutput"><span class="identifier">cls</span><span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">name</span><span class="special">,</span> <span class="identifier">visitor</span><span class="special">,</span> <span class="identifier">options</span><span class="special">)</span></code> forwards to this member
                          function.
                        </p>
                      </td>
</tr>
</tbody>
</table></div>
</dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="high_level_components.boost_python_def_visitor_hpp.example"></a><a class="link" href="boost_python_def_visitor_hpp.html#high_level_components.boost_python_def_visitor_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">X</span> <span class="special">{/*...*/};</span>

<span class="keyword">class</span> <span class="identifier">my_def_visitor</span> <span class="special">:</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">def_visitor</span><span class="special">&lt;</span><span class="identifier">my_def_visitor</span><span class="special">&gt;</span>
<span class="special">{</span>
  <span class="keyword">friend</span> <span class="keyword">class</span> <span class="identifier">def_visitor_access</span><span class="special">;</span>

  <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">classT</span><span class="special">&gt;</span>
  <span class="keyword">void</span> <span class="identifier">visit</span><span class="special">(</span><span class="identifier">classT</span><span class="special">&amp;</span> <span class="identifier">c</span><span class="special">)</span> <span class="keyword">const</span>
  <span class="special">{</span>
    <span class="identifier">c</span><span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"foo"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">my_def_visitor</span><span class="special">::</span><span class="identifier">foo</span><span class="special">);</span>
    <span class="identifier">c</span><span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"bar"</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">my_def_visitor</span><span class="special">::</span><span class="identifier">bar</span><span class="special">);</span>
  <span class="special">}</span>

  <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">foo</span><span class="special">(</span><span class="identifier">X</span><span class="special">&amp;</span> <span class="identifier">self</span><span class="special">);</span>
  <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">bar</span><span class="special">(</span><span class="identifier">X</span><span class="special">&amp;</span> <span class="identifier">self</span><span class="special">);</span>
<span class="special">};</span>

<span class="identifier">BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">my_ext</span><span class="special">)</span>
<span class="special">{</span>
  <span class="identifier">class_</span><span class="special">&lt;</span><span class="identifier">X</span><span class="special">&gt;(</span><span class="string">"X"</span><span class="special">)</span>
    <span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="identifier">my_def_visitor</span><span class="special">());</span>
<span class="special">}</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_def_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../high_level_components.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_docstring_options_h.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>
